package top.fengleifeng.question;

/**
 * @program: leetcode-test
 * @description:
 * @author: fengleifeng
 * @create: 2020-10-19 10:26
 **/
public class Num746使用最小花费爬楼梯 {
    class Solution {
        public int minCostClimbingStairs(int[] cost) {
            if (cost.length <= 2) {
                if (cost.length == 0) {
                    return 0;
                } else if (cost.length == 1) {
                    return cost[0];
                } else if (cost.length == 2) {
                    return Math.min(cost[0], cost[1]);
                }
            }
            int length = cost.length;
            int[] test = new int[cost.length];
            test[0] = cost[0];
            test[1] = cost[1];
            for (int i = 2; i < length; i++) {
                test[i] = Math.min(test[i-1],test[i-2]) +cost[i];
            }
            return Math.min(test[length - 1], test[length - 2]);
        }
    }

    public static void main(String[] args) {
        int[] ints = {0,0,1,1};
        int i = new Num746使用最小花费爬楼梯().new Solution().minCostClimbingStairs(ints);
        System.out.println(i);
    }
}
